import { AtSearchBar } from 'taro-ui'
import { useEffect, useState } from 'react'
import Taro from '@tarojs/taro'
import Router from 'tarojs-router-next'
import env from '../../../store/env.config'

const MySearch = ({ userInfo }) => {
  const [searchVal, setSearchVal] = useState('')

  const to = () => {
    Taro.request({
      url: `${env.domain}/goods/list`,
      data: {
        page: 1,
        pageSize: 10000,
        name: searchVal,
        token: userInfo['auth'],
      },
      success: (requestData) => {
        Router.navigate({ url: '/pages/goods/goods' }, { data: requestData })
      },
    })
  }

  return (
    <AtSearchBar
      actionName='搜索商品'
      value={searchVal}
      onChange={(val) => setSearchVal(val)}
      onActionClick={to}
    />
  )
}
export default MySearch
